/**
 *	\file CDSQStateMaintainer.h
 *  
 *  \section desc_sec Description
 *  Description
 *  
 *  \if copyright
 *  	Copyright 2008 Jeffrey Zhang. All rights reserved.
 *  \endif
 *  
 *  \section hist_sec Change History:
 *  	-	2/11/08		Jeffrey Zhang		Created this file
 *  
 *  <hr>
 *  \addtogroup AKCPP
 *  @{
 */

#ifndef _CDSQSTATEMAINTAINER_H
#define _CDSQSTATEMAINTAINER_H

#include "Abstractclasses.h"
#include "Algorithm.h"

class CDSQStateMaintainer : public AKCPPStateMaintainer
{
public:
	CDSQStateMaintainer(unsigned int aNumOfSides);
	virtual ~CDSQStateMaintainer(void);
		
	virtual void backToInitialState();
	virtual bool performMove(const AKMove newMove);
	virtual bool canUndo();
	virtual bool undo();
	
	//Piece Infomation
	virtual const vector<AKPiece>*	getCreatedPieces();
	virtual const vector<AKPiece>*	getElminatedPieces();
	virtual const vector<AKMove>*	getMovedPieces();
	virtual const vector<AKPiece>*	getAllPieces();
	virtual const vector<AKPiece>*		getPlaceablePiecesAtCell(const AKCellIndex);
	virtual const vector<AKCellIndex>*	getReachableCellsForPiece(const AKPiece piece);
	
	virtual const AKSideIndex getNextPlayerSide();
	virtual const vector<AKSideIndex>*	getWinners();
	
	virtual const AKMove getAlternativeMoveForNextPlayer();
	
protected:
	int IsValidMove(PieceIndex position[][9], int nFromX, int nFromY, int nToX, int nToY);
	unsigned int MakeMove(PieceMove* move);
	void UnMakeMove(PieceMove* move,unsigned int type);
	
private:
	AKMove lastMove;
	AKPieceIndex undotype;
	AKSideIndex nextPlayer;
	
	vector<AKSideIndex> *winners;
	vector<AKCellIndex>	*reachableCells;
	vector<AKPiece>		*somePieces;
	vector<AKPiece>		*allPieces;
	vector<AKMove>		*movedPieces;
	
	PieceIndex CurPosition[7][9];
};

#endif //_CDSQSTATEMAINTAINER_H

/** @} */

